package db.migration;

import net.jiastudy.biz.user.entity.Role;
import net.jiastudy.biz.user.service.RoleService;
import net.jiastudy.core.base.BaseMigration;
import net.jiastudy.core.common.SysRole;
import net.jiastudy.core.utils.SpringUtility;

import java.util.HashSet;
import java.util.Set;

public class V1_0_3__init_role extends BaseMigration {
    private RoleService roleService = SpringUtility.getBean(RoleService.class);

    @Override
    public void migrate() throws Exception {
        Set<String> permissions = new HashSet<>();
        permissions.add("task:menu");
        permissions.add("task:dept");

        permissions.add("task:audit");
        permissions.add("task:enter");
        permissions.add("task:statistics");
        this.createRole(SysRole.ROLE_USER, permissions);
    }

    private void createRole(SysRole sysRole, Set<String> permissions) {
        Role role = new Role();
        role.setCode(sysRole.name());
        role.setName(sysRole.getDesc());
        role.setPermissions(permissions);
        role.setSysRole(false);
        roleService.createRole(role);
    }
}
